package com.hhh.petadopt.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhh.petadopt.mapper.IndexMapper;
import com.hhh.petadopt.pojo.Lost;
import com.hhh.petadopt.pojo.News;
import com.hhh.petadopt.service.IndexService;
/**
 * 首页内容展示
 * @author 杜镇声声
 *
 */
@Service
public class IndexServiceImpl implements IndexService {
	@Autowired
	private IndexMapper indexMapper;

	//查询前四条轮播图信息
	@Override
	public List<Lost> LunBoTu() {
		List<Lost> lostList = indexMapper.selectfourpic();
		return lostList;
	}

	//查找热点新闻
	@Override
	public List<News> selecthotNews() {
		List<News> HotNewsList = indexMapper.selectHotNews();
		
		/*List<News> selectNewsByVo = adminnewsmapper.selectNewsByVo(Vo);
		List<News> nList = new ArrayList<News>();
		for (News news : selectNewsByVo) {
			news.setCreated(news.getCreated().substring(0, 10));
			nList.add(news);
		}*/
		//将日期转换为yyyy-mm-dd格式
		List<News> nList = new ArrayList<News>();
		for (News news : HotNewsList) {
			news.setCreated(news.getCreated().substring(0, 10));
			nList.add(news);
		}
		return nList;
	}

	//查找普通新闻
	@Override
	public List<News> selectNormalNews() {
		List<News> norbmalList = indexMapper.selectNormalNews();
		List<News> nList = new ArrayList<News>();
		for (News news : norbmalList) {
			news.setCreated(news.getCreated().substring(0, 10));
			nList.add(news);
		}
		return nList;
	}

	//查询更改热点新闻列表
	@Override
	public List<News> selectHotNewsList() {
		List<News> HotList = indexMapper.selectHotNewsList();
		//将日期转换为yyyy-mm-dd格式
		List<News> nList = new ArrayList<News>();
		for (News news : HotList) {
			news.setCreated(news.getCreated().substring(0, 10));
			nList.add(news);
		}
		return nList;
	}

	//查询更多普通新闻
	@Override
	public List<News> selectMoreNorMalNewsList() {
		List<News> selectMoreNorMalNewsList = indexMapper.selectMoreNorMalNewsList();
		//将日期转换为yyyy-mm-dd格式
		List<News> nList = new ArrayList<News>();
		for (News news : selectMoreNorMalNewsList) {
			news.setCreated(news.getCreated().substring(0, 10));
			nList.add(news);
		}
		return nList;
	}

}
